package com.bysj.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bysj.entity.RenCai;
import com.bysj.fenye.pagevo.RenCaiPageVO;
import com.bysj.service.RenCaiService;
import com.bysj.service.impl.RenCaiServiceImpl;

public class RenCaiServlet extends HttpServlet {
	private RenCaiService rcs=new RenCaiServiceImpl();
	private RenCaiPageVO pagevo=new RenCaiPageVO(10);
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String m=request.getParameter("m");
		String method=request.getParameter("method");
		if("pre".equals(method)){
			this.pagevo.setPrevious();
		}else if("next".equals(method)){
			this.pagevo.setNext();
		}else if("last".equals(method)){
			this.pagevo.setLast();
		}else if("index".equals(method)){
			String ind=request.getParameter("ind");
			this.pagevo.setIndex(Integer.parseInt(ind.trim()));
		}else{
			this.pagevo.setFirst();
		}
		if("AllRenCai".equals(m)){
			request.getSession().setAttribute("rlist", pagevo);
			request.getRequestDispatcher("../rencai/allrencai.jsp").forward(request, response);
		}else if("DelRenCai".equals(m)){
			Integer id=Integer.parseInt(request.getParameter("id"));
			RenCai rc=new RenCai();
			rc.setId(id);
			rcs.delRenCai(rc);
			request.getSession().setAttribute("rlist", pagevo);
			request.getRequestDispatcher("../rencai/allrencai.jsp").forward(request, response);
		}else if("DetailRenCai".equals(m)){
			Integer id=Integer.parseInt(request.getParameter("id"));
			RenCai rc=new RenCai();
			rc.setId(id);
			RenCai rcncai=rcs.queryRenCai(rc);
			request.getSession().setAttribute("rlist", rcncai);
			request.getRequestDispatcher("../rencai/rcdetail.jsp").forward(request, response);

		}else if("AddNewRenCai".equals(m)){
			String title=request.getParameter("title");
			String time=request.getParameter("time");
			String type=request.getParameter("type");
			String content=request.getParameter("rencaiFCKeditor");
			System.out.println(title+"----"+time+"------"+type+"------"+content);

			RenCai rc=new RenCai();
			rc.setTitle(title);
			rc.setTime(time);
			rc.setContent(content);
			rc.setType(type);
			rcs.addRenCai(rc);
			request.getSession().setAttribute("rlist", pagevo);
			request.getRequestDispatcher("../rencai/allrencai.jsp").forward(request, response);
		}else if("updateRenCaiDoc".equals(m)){
			request.getSession().setAttribute("updaterencaidocByid", request.getParameter("id"));
			request.getRequestDispatcher("../rencai/updatercDoc.jsp").forward(request, response);
		
		}

	}

}
